<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript">

    function validateComment() {
        var commentValue = $('#comment').val();
        if (commentValue.length <= 0) {
            validateRejectAndMail();
        }
    }

    function validateRejectAndMail() {
        $('#comment').rules("add", {
            required:true,
            messages:{
                required: " Please Enter a Comment " }
        });
    }

    $(function () {
        var email = $('#emailId').val();
        if (email != null && email.length > 0) {
            $('#sendMail').show();
        } else {
            $('#sendMail').hide();
        }
    });

    function validateRejection(elementId) {
           // $('#rejectComment').show()
            var comment_on_rejection= $('#pls_enter_comment_on_rejection').val();

            //alert($('#' +elementId).val());

            $('#' +elementId).rules("add", {
                required:true,
                messages:{
                    required:comment_on_rejection }
            });
     }

</script>
<div class="form-button-div left-align">
    <s:if test="editMode!=0">
        <tr>
            <td><s:label value="%{getText('status.label')}"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td>
                <s:label name="landApplication.initialStatus"/>
            </td>
        </tr>
    </s:if>
</div>

<s:if test="landApplication.comment != null && landApplication.comment.length() > 0">
    <table class="width-100">
        <tr>
            <td><s:label value="%{getText('comments_history.label')}"/></td>
            <td colspan="3">
                <s:textarea id="viewComment" readonly="true" name="landApplication.comment" cssClass="width-595-px"/>
            </td>
        </tr>
    </table>
</s:if>

<s:if test="editMode==2 ">
    <table class="width-100">
        <tr>
            <td><s:label value="%{getText('application_comment.label')}"/></td>
            <td colspan="3">
                <s:textarea id="commentId" name="comment" cssClass="width-595-px"/>
            </td>
        </tr>
    </table>
</s:if>

<s:if test="searchValue != 1">

    <div class="form-button-div right-align" id="save-cancel">
        <s:hidden name="landApplication.id"/>
        <s:hidden name="landApplication.version"/>
        <s:if test="#session.userGroup =='slc'">
            <s:if test="editMode==1">
                <%--<s:hidden name="editMode" value="1"/>--%>
                <%-- <s:hidden name="applicationId"/>--%>
                <s:submit action="addInitLandApplicationByApplicant" value="Save"/>
                <s:hidden name="contacts.id"/>
                <s:hidden name="holder.id"/>
                <s:hidden name="contactPerson.id"/>
            </s:if>
            <s:else>
                <s:submit cssClass="cancel" action="homeApplicant" value="%{getText('cancel.label')}"/>
            </s:else>
        </s:if>
        <s:elseif test="#session.userGroup =='onla'">
             <s:submit action="onlineApplicationSave" value="Save"/>
             <s:submit cssClass="cancel" action="welcome" value="Cancel"/>
        </s:elseif>
        <s:else>
            <s:if test="editMode==0">
                <%--<s:hidden name="editMode" value="0"/>--%>
                <s:submit action="addInitLandApplication" value="%{getText('save.label')}"/>
                <s:submit cssClass="cancel" action="landAlienationModuleHome" value="%{getText('cancel.label')}"/>
            </s:if>
            <s:elseif test="editMode==1">
                <%--<s:hidden name="editMode" value="1"/>--%>
                <%-- <s:hidden name="applicationId"/>--%>

                <s:submit action="addInitLandApplication" value="%{getText('edit.label')}"/>
                <s:submit cssClass="cancel" action="landAlienationModuleHome" value="%{getText('cancel.label')}"/>
                <s:hidden name="contacts.id"/>
                <s:hidden name="holder.id"/>
                <s:hidden name="contactPerson.id"/>
            </s:elseif>
            <s:elseif test="editMode==2">
                <s:hidden name="applicationId"/>
                <s:submit value="%{getText('approve_button.label')}" action="approveInitApplication"/>
                <s:submit value="%{getText('reject_button.label')}" action="rejectInitApplication" onclick="javascript:return validateRejection('commentId')"/>
                <s:submit id="sendMail" value="%{getText('send_mail_button.label')}" action="sendMailInitApplication"/>

                <%--<s:url id="rejectInitApplication" action="rejectInitApplication">
                    <s:param name="applicationId" value="landApplication.id"/>
                </s:url>
                <s:url id="approveApplication" action="approveInitApplication">
                    <s:param name="applicationId" value="landApplication.id"/>
                </s:url>
                <s:url id="sendMailInitApplication" action="sendMailInitApplication">
                    <s:param name="applicationId" value="landApplication.id"/>
                </s:url>

                <s:a href="%{approveApplication}">
                    <s:submit value="%{getText('approve_button.label')}"/>
                </s:a>
                <s:a href="%{rejectInitApplication}">
                    <s:submit value="%{getText('reject_button.label')}"/>
                </s:a>
                <s:a href="%{sendMailInitApplication}">
                    <s:submit id="sendMail" value="%{getText('send_mail_button.label')}"/>
                </s:a>--%>
            </s:elseif>
        </s:else>
            <%--<s:hidden name="initApplicationId" value="0"/>--%>
    </div>
    <%--<s:hidden id="email" name="contacts.email"/>--%>
</s:if>

<s:hidden id="pls_enter_comment_on_rejection" value="%{getText('pls_enter_comment_on_rejection.label')}"/>